package LeetcodeTest_twenty_three;
//买股票最佳时机

public class maxProfits
{
    public static void main(String[] args)
    {
        int[] prices={7,1,5,3,6,4};
        System.out.println(solution.maxProfit(prices));
    }
}
class solution
{
    public static int maxProfit(int[] prices)
    {
        if(prices.length<2)
            return 0;
        int i,sub;
        sub=0;
        for(i=0;i<prices.length-1;i++)
        {
            if(prices[i+1]>prices[i])
                sub+=prices[i+1]-prices[i];
        }
        return sub;
    }
}